#include "effect.h"

void Effect::lucencyImgOverlay(cv::Mat &lucencyImg, cv::Mat &backgroudImg, cv::Point point) {
// 图像叠加函数的实现
    int channelNum = 3, alpha = 0;  //rgb通道数和透明度值，0完全透明，1为完全不透明

    for (int row = 0; row < lucencyImg.rows; row++) {
        for (int col = 0; col < lucencyImg.cols; col++) {
            alpha = lucencyImg.ptr<int>(row, col)[3];   //alpha通道

            if (alpha != 0) {   //不透明区域，对背景图片进行叠加
                if ( (row + point.y <= backgroudImg.rows) && (row + point.y >= 0) &&
                     (col + point.x <= backgroudImg.cols) && (col + point.x >= 0) ) {
                    for (int i = 0; i < channelNum; i++)    //不透明区域赋值
                        backgroudImg.ptr<int>(point.y + row, point.x + col)[i] = lucencyImg.ptr<int>(row, col)[i];
                }
            }

        }
    }
}
